package com.jn.gsondemo.adapter;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.gsondemo.R;
import com.jn.gsondemo.entity.MedalData;

import java.util.List;

public class MedalRankAdapter extends RecyclerView.Adapter<MedalRankAdapter.ViewHolder> {
    private List<MedalData> medalList;

    public MedalRankAdapter(List<MedalData> medalList) {
        this.medalList = medalList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_medal, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        MedalData medalData = medalList.get(position);
        holder.rank.setText(medalData.getRank());
        holder.countryName.setText(medalData.getCountryname());
        holder.gold.setText(medalData.getGold());
        holder.silver.setText(medalData.getSilver());
        holder.bronze.setText(medalData.getBronze());
    }

    @Override
    public int getItemCount() {
        return medalList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView rank, countryName, gold, silver, bronze;

        ViewHolder(View itemView) {
            super(itemView);
            rank = itemView.findViewById(R.id.rank);
            countryName = itemView.findViewById(R.id.country_name);
            gold = itemView.findViewById(R.id.gold);
            silver = itemView.findViewById(R.id.silver);
            bronze = itemView.findViewById(R.id.bronze);
        }
    }
}